﻿<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Inner.Master"
    CodeBehind="AppointmentDetails.aspx.vb" Inherits="LecturerAppointmentSystem.AppointmentDetails" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="Style.css" rel="stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
    <br />
    <center>
            <asp:Label ID="lbl_BookingConfirmation" runat="server" Visible="False" 
                    ForeColor="Red"></asp:Label>
                    </center>
    <br />
    <asp:MultiView ID="AppointmentDetailsMultiView" runat="server">
        <asp:View ID="LecturerView" runat="server">
            <center>
           <br />
                <asp:DetailsView ID="LecturerDetailsView" runat="server" AutoGenerateRows="False" DataSourceID="LecturerAppointmentDetailsDataSource"
                    EnableModelValidation="True" Height="50%" Width="20%">
                    <Fields>
                        <asp:BoundField DataField="AppointmentDate" DataFormatString="{0:d}" HeaderText="Date"
                            SortExpression="AppointmentDate" />
                        <asp:BoundField DataField="TimeSlot" HeaderText="Time" SortExpression="TimeSlot" />
                        <asp:BoundField DataField="Place" HeaderText="Place" SortExpression="Place" />
                        <asp:BoundField DataField="Agenda" HeaderText="Agenda" SortExpression="Agenda" />
                        <asp:CheckBoxField DataField="Booked" HeaderText="Booked" SortExpression="Booked" />
                        <asp:TemplateField HeaderText="Name" SortExpression="Student_FirstName">
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("Student_FirstName") & " " & Bind("Student_LastName") %>'></asp:Label></ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" SortExpression="ID"
                            Visible="False" />
                    </Fields>
                </asp:DetailsView>
            </center>
            <asp:SqlDataSource ID="LecturerAppointmentDetailsDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:AppointmentsConnectionString %>"
                ProviderName="<%$ ConnectionStrings:AppointmentsConnectionString.ProviderName %>"
                SelectCommand="SELECT [AppointmentDate], [TimeSlot], [Place], [Agenda], [Booked], [Student_FirstName], [Student_LastName], [ID] FROM [AppointmentsWithLecturerAndStudentDetails] WHERE ([ID] = ?)">
                <SelectParameters>
                    <asp:QueryStringParameter Name="ID" QueryStringField="ID" Type="Int32" />
                </SelectParameters>
            </asp:SqlDataSource>
        </asp:View>
        <asp:View ID="StudentView" runat="server">
            <br />
            <center>
                <asp:DetailsView ID="StudentDetailsView" runat="server" AutoGenerateRows="False" DataSourceID="StudentAppointmentDetailsDataSource"
                    EnableModelValidation="True" Height="50%" Width="20%" CssClass="DetailsViewClass">
                    <Fields>
                        <asp:BoundField DataField="AppointmentDate" DataFormatString="{0:d}" HeaderText="Date"
                            SortExpression="AppointmentDate" />
                        <asp:BoundField DataField="TimeSlot" HeaderText="Time" SortExpression="TimeSlot" />
                        <asp:BoundField DataField="Place" HeaderText="Place" SortExpression="Place" />
                        <asp:BoundField DataField="Agenda" HeaderText="Agenda" SortExpression="Agenda" />
                        <asp:TemplateField HeaderText="Name" SortExpression="Lecturer_FirstName">
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Eval("Lecturer_FirstName") & " " & Eval("Lecturer_LastName") %>'></asp:Label></ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" SortExpression="ID"
                            Visible="False" />
                    </Fields>
                </asp:DetailsView>
                <asp:Button ID="btn_Book" runat="server" Text="Book" />
                <asp:ModalPopupExtender ID="BookPopup" runat="server" TargetControlID="btn_Book"
                    PopupControlID="BookPanel" CancelControlID="btn_CancelBook">
                </asp:ModalPopupExtender>
                <br />
                <asp:Panel ID="BookPanel" runat="server" CssClass="modalPopupPanel">
                    <asp:Label ID="lbl_BookConfirmation" runat="server" Text="Are you sure you want to book this appointment?"></asp:Label>
                    <asp:DetailsView ID="AppointmentConfirmation" runat="server" AutoGenerateRows="False" DataSourceID="StudentAppointmentDetailsDataSource"
                    EnableModelValidation="True" Height="50px" Width="125px" CssClass="DetailsViewClass">
                    <Fields>
                        <asp:BoundField DataField="AppointmentDate" DataFormatString="{0:d}" HeaderText="Date"
                            SortExpression="AppointmentDate" />
                        <asp:BoundField DataField="TimeSlot" HeaderText="Time" SortExpression="TimeSlot" />
                        <asp:BoundField DataField="Place" HeaderText="Place" SortExpression="Place" />
                        <asp:TemplateField HeaderText="Name" SortExpression="Lecturer_FirstName">
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Eval("Lecturer_FirstName") & " " & Eval("Lecturer_LastName") %>'></asp:Label></ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" SortExpression="ID"
                            Visible="False" />
                    </Fields>
                </asp:DetailsView>
                    <br />
                    <div style="text-align: right;">
                        <asp:Button ID="btn_YesBook" runat="server" Text="Yes" />
                        &nbsp
                        <asp:Button ID="btn_CancelBook" runat="server" Text="Cancel" />
                    </div>
                </asp:Panel>
                <asp:ModalPopupExtender ID="AgendaPopup" runat="server" TargetControlID="btn_YesBook"
                    CancelControlID="cancel" PopupControlID="AgendaPanel">
                </asp:ModalPopupExtender>
                <asp:Panel ID="AgendaPanel" runat="server" CssClass="modalPopupPanel">
                    <asp:Label ID="lbl_Agenda" runat="server" Text="Please enter an agenda for the appointment"></asp:Label>
                    <br />
                    <asp:TextBox ID="tb_agenda" runat="server" TextMode="MultiLine"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="AgendaRequired" runat="server" 
                    ControlToValidate="tb_agenda" ErrorMessage="Please give a reason for the appointment" 
                    Display="Dynamic" SetFocusOnError="true">*</asp:RequiredFieldValidator>
                    <div style="text-align: right;">
                        <asp:Button ID="btnBook" runat="server" Text="Book" OnClick="BookAppointment" CausesValidation="true" />
                        <asp:Button ID="cancel" runat="server" Text="Cancel" />
                    </div>
                </asp:Panel>
                <br />
                <asp:SqlDataSource ID="StudentAppointmentDetailsDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:AppointmentsConnectionString %>"
                    ProviderName="<%$ ConnectionStrings:AppointmentsConnectionString.ProviderName %>"
                    SelectCommand="SELECT [AppointmentDate], [TimeSlot], [Place], [Agenda], [Lecturer_FirstName], [Lecturer_LastName], [ID] FROM [AppointmentsWithLecturerAndStudentDetails] WHERE ([ID] = ?)">
                    <SelectParameters>
                        <asp:QueryStringParameter Name="ID" QueryStringField="ID" Type="Int32" />
                    </SelectParameters>
                </asp:SqlDataSource>
                
            </center>
        </asp:View>
    </asp:MultiView>
    <center>
    
        <asp:Button ID="btn_Cancel" runat="server" Text="Cancel Appointment" />
        <asp:Button ID="btn_Reschedule" runat="server" Text="Reschedule" />
        <br />
        <asp:ModalPopupExtender ID="CancelAppointmentPopup" runat="server" TargetControlID="btn_Cancel"
            PopupControlID="CancelPanel" CancelControlID="ButtonCancel">
        </asp:ModalPopupExtender>
        <asp:Panel ID="CancelPanel" runat="server" CssClass="modalPopupPanel">
            <asp:Label ID="lbl_Reason" runat="server" Text="Please give a reason for cancelling the appointment"></asp:Label>
            <br />
            <br />
            <asp:TextBox ID="tb_Reason" runat="server" TextMode="MultiLine"></asp:TextBox>
            <asp:RequiredFieldValidator ID="ReasonRequired" runat="server" 
                    ControlToValidate="tb_Reason" ErrorMessage="Reason for cancellation is required" 
                    Display="Dynamic" SetFocusOnError="true">*</asp:RequiredFieldValidator>
            <br />
            <br />
            <div style="text-align: right;">
                <asp:Button ID="ButtonSend" runat="server" Text="Send" CommandName="Send" 
                OnClick="ButtonSend_Click" CausesValidation="true" />
                &nbsp
                <asp:Button ID="ButtonCancel" runat="server" Text="Cancel" />
            </div>
        </asp:Panel>
        <br />
        <asp:ModalPopupExtender ID="ReschedulePopup" runat="server" TargetControlID="btn_Reschedule"
            PopupControlID="ReschedulePanel" CancelControlID="btnRescheduleCancel">
        </asp:ModalPopupExtender>
        <asp:Panel ID="ReschedulePanel" runat="server" CssClass="modalPopupPanel">
            <asp:Label ID="RescheduleLabel" runat="server" Text="Are you sure you want to reschedule this appointment?"></asp:Label>
            <br />
            <br />
            <asp:Button ID="btnRescheduleYes" runat="server" Text="Yes" />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Button ID="btnRescheduleCancel" runat="server" Text="Cancel" />            
        </asp:Panel>
        <asp:Label ID="lbl_MailError" runat="server" ForeColor="Red"></asp:Label>
       
    </center>
    <br />
</asp:Content>
